package leetcode;

import java.util.Arrays;

public class youxiaosanjiaoxgeshu {
    public static int triangleNumber(int[] nums) {
        if(nums==null||nums.length==0){
            return  -1;
        }
        //给数组先排序
        Arrays.sort(nums);
        int c=0;
        int b=0;
        int a=0;
        int sum=0;
        for(int i=nums.length-1;i>=0;i--){
            //每次要重新置定为0
            a=0;
            c=i;
            b=i-1;
            while(a!=b&&b>=0){
                if(nums[a]+nums[b]>nums[c]){
                    sum=sum+b-a;
                    b--;
                }else{
                    a++;
                }
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        int[] array={2,2,3,4};
        int i = triangleNumber(array);
        System.out.println(i);


    }
}
